package com.dataseek.iot.sys.manager.handler;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dataseek.iot.core.response.ResponseEntity;
import com.dataseek.iot.core.handler.ServiceHandler;
import com.dataseek.iot.mysql.entity.District;
import com.dataseek.iot.mysql.service.impl.DistrictServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * @author cc
 * @Title: 区域服务handler
 * @Description: 区域服务handler
 * @date 2021/9/69:14 下午
 * @since 1.0
 */
@Component
@Slf4j
public class DistrictServiceHandler extends ServiceHandler<District> {

    @Autowired
    DistrictServiceImpl districtService;



    @Override
    public Mono<ResponseEntity> saveOne(Object entity) {
        Boolean b = districtService.save((District) entity);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> saveBatch(List lists) {
        Boolean b = districtService.saveBatch(lists);
        return this.createResponse(b);
    }


    @Override
    public Mono<ResponseEntity> removeById(String id) {
        Boolean b = districtService.removeById(id);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> removeAll(List ids) {
        Boolean b = districtService.removeByIds(ids);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> updateOne(Object entity) {
        Boolean b = districtService.updateById((District) entity);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> updateBatch(List entities) {
        Boolean b =  districtService.updateBatchById(entities);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> findOne(String id) {
        District district = districtService.getById(id);
        return this.createResponse(district);
    }

    @Override
    public Mono<ResponseEntity> page(Page p) {
        Page authPage = districtService.page(p);
        return this.createResponse(authPage);
    }

    @Override
    public Mono<ResponseEntity> page(Page p, Wrapper wrapper) {
        Page authPage = districtService.page(p, wrapper);
        return this.createResponse(authPage);
    }

    @Override
    public Flux<ResponseEntity> find(List ids) {
        List<District> lists = districtService.listByIds(ids);
        return this.createResponse(lists);
    }

    @Override
    public Flux<ResponseEntity> find(Wrapper wrapper) {
        List<District> lists = districtService.list(wrapper);
        return this.createResponse(lists);
    }

    @Override
    public Flux findAll() {
        List<District> lists = districtService.list();
        return this.createResponse(lists);
    }

    @Override
    public Mono<ResponseEntity> remove(Wrapper wrapper) {
        Boolean b = districtService.remove(wrapper);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> remove(String id) {
        Boolean b = districtService.removeById(id);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> update(Wrapper wrapper) {
        Boolean b = districtService.update(wrapper);
        return this.createResponse(b);
    }

    @Override
    public Mono<ResponseEntity> defaultResponseOne(ResponseEntity responseEntity) {
        return Mono.just(responseEntity);
    }

    @Override
    public Flux<ResponseEntity> defaultResponseTwo(ResponseEntity responseEntity) {
        return Flux.just(responseEntity);
    }

}
